using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.DriftBottle.Scene;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class BotterDetailInfo : BasePage
	{
		private const string TAG = "BotterDetailInfo";
		private BottleContact mContact;
		private string mStrBtterName;
		private EventWatcher mWatcherSayHi;
		private EventWatcher mWatcherHeadImgAdd;
		private EventWatcher mWatcherExpose;
		private string mStrSayHiOrigin = "";
		internal Grid LayoutRoot;
		internal StackPanel panelProfile;
		internal ProfileTopInfoCtrl topInfoCtrl;
		internal StackPanel panelContentInfo;
		internal Grid panelAblum;
		internal ProfileTxtContentCtrl ctrlArea;
		internal ProfileTxtContentCtrl ctrlVerify;
		internal Button btnSendInvite;
		internal Button btnExpose;
		private bool _contentLoaded;
		public BotterDetailInfo()
		{
			this.InitializeComponent();
			this.SetAppBar();
			base.add_Loaded(new RoutedEventHandler(this.Page_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.Page_Unloaded));
		}
		private void Page_Loaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("BotterDetailInfo", "Page_Loaded");
		}
		private void Page_Unloaded(object sender, RoutedEventArgs e)
		{
			Log.smethod_5("BotterDetailInfo", "Page_Loaded");
		}
		protected override void OnPageIn(object[] object_0)
		{
			Log.smethod_5("BotterDetailInfo", "OnPageIn");
			if (object_0 != null && 1 == object_0.Length)
			{
				if (object_0[0].GetType() == typeof(BottleContact) || object_0[0].GetType() == typeof(string))
				{
					this.registerEvent();
					if (object_0[0] is BottleContact)
					{
						this.mContact = (object_0[0] as BottleContact);
					}
					else
					{
						if (object_0[0] is string)
						{
							this.mStrBtterName = (object_0[0] as string);
							string gparam_ = BContactMgr.toBottleContactUserName(this.mStrBtterName);
							this.mContact = StorageMgr.bContact.method_0(gparam_);
						}
					}
					if (this.mContact != null && this.mContact.strUserName != null)
					{
						this.initUI();
						return;
					}
					base.GoBack();
					return;
				}
			}
			base.GoBack();
		}
		protected override void OnPageOut()
		{
			Log.smethod_5("BotterDetailInfo", "OnPageOut");
			this.unRegisterEvent();
		}
		protected override void OnPageBack()
		{
			Log.smethod_5("BotterDetailInfo", "OnPageBack");
		}
		private void registerEvent()
		{
			if (this.mWatcherSayHi == null)
			{
				this.mWatcherSayHi = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerSayHi));
				EventCenter.registerEventWatcher(EventConst.ON_LBS_SAYHI_SUCCESS, this.mWatcherSayHi);
				EventCenter.registerEventWatcher(EventConst.ON_LBS_SAYHI_ERROR, this.mWatcherSayHi);
			}
			if (this.mWatcherHeadImgAdd == null)
			{
				this.mWatcherHeadImgAdd = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerHeadImgAdd));
				EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
			}
			if (this.mWatcherExpose == null)
			{
				this.mWatcherExpose = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerExpose));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_EXPOSE_SUCCESS, this.mWatcherExpose);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_EXPOSE_ERR, this.mWatcherExpose);
			}
		}
		private void unRegisterEvent()
		{
			if (this.mWatcherSayHi != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_LBS_SAYHI_SUCCESS, this.mWatcherSayHi);
				EventCenter.removeEventWatcher(EventConst.ON_LBS_SAYHI_ERROR, this.mWatcherSayHi);
				this.mWatcherSayHi = null;
			}
			if (this.mWatcherHeadImgAdd != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
				this.mWatcherHeadImgAdd = null;
			}
			if (this.mWatcherExpose != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_EXPOSE_SUCCESS, this.mWatcherExpose);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_EXPOSE_ERR, this.mWatcherExpose);
				this.mWatcherExpose = null;
			}
		}
		private void onEventHandlerSayHi(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (EventConst.ON_LBS_SAYHI_SUCCESS == evtArgs.mEventID)
			{
				MessageBoxManager.ShowToast(strings.Lbs_PeoInfo_MsgSayHiSucc, 2500, null, false);
				Log.smethod_5("BotterDetailInfo", "ON_LBS_SAYHI_SUCCESS");
				return;
			}
			if (EventConst.ON_LBS_SAYHI_ERROR == evtArgs.mEventID && evtArgs.mObject != null)
			{
				RetConst retConst = (RetConst)evtArgs.mObject;
				if (RetConst.MM_ERR_CLIENT == retConst)
				{
					MMMessageBox.Show(strings.Con_Detail_MsgBadNet, true, "确定");
				}
				else
				{
					if (RetConst.MM_ERR_SPAM == retConst)
					{
						MMMessageBox.Show(strings.Con_Detail_MsgSpam, true, "确定");
					}
					else
					{
						if (RetConst.MM_ERR_FREQ_LIMITED == retConst)
						{
							MMMessageBox.Show(strings.Lbs_PeoInfo_MsgTooFreq, true, "确定");
						}
						else
						{
							if (RetConst.MM_ERR_BOTTLEBANBYEXPOSE == retConst)
							{
								MMMessageBox.Show(strings.Lbs_PeoInfo_MsgBadMan, true, "确定");
							}
							else
							{
								if (RetConst.MM_ERR_BLACKLIST == retConst)
								{
									MMMessageBox.Show(strings.Lbs_PeoInfo_MsgBeBlocked, true, "确定");
								}
								else
								{
									MMMessageBox.Show(strings.Con_Detail_MsgSendFailed, true, "确定");
								}
							}
						}
					}
				}
				Log.smethod_5("BotterDetailInfo", "ON_LBS_SAYHI_ERROR:" + retConst);
			}
		}
		private void onEventHandlerHeadImgAdd(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<string> listObject = evtArgs.getListObject<string>();
			if (listObject == null)
			{
				return;
			}
			if (this.mContact != null && !string.IsNullOrEmpty(this.mContact.strUserName))
			{
				using (List<string>.Enumerator enumerator = listObject.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string current = enumerator.get_Current();
						if (current != null && current.GetType() == typeof(string) && current == this.mContact.strUserName)
						{
							this.topInfoCtrl.imgHead.set_Source(HeadImgMgr.getHeadImage(this.mContact));
						}
					}
				}
				return;
			}
		}
		private void onEventHandlerExpose(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			if (EventConst.ON_NETSCENE_EXPOSE_SUCCESS == evtArgs.mEventID)
			{
				MessageBoxManager.ShowToast(strings.Lbs_PeoInfo_MsgExposeSucc, 2500, null, false);
				return;
			}
			if (EventConst.ON_NETSCENE_EXPOSE_ERR == evtArgs.mEventID)
			{
				MMMessageBox.Show(strings.Lbs_PeoInfo_MsgExposeFail, true, "确定");
			}
		}
		private void topInfoCtrl_mImgHeadClicked(object sender, object args)
		{
			base.GoToPage("/Source/UI/Contact/HighQualityHeadImgView.xaml", new object[]
			{
				args,
				this.mContact.strUserName,
				sender
			}, false);
		}
		private void btnSendInvite_Click(object sender, RoutedEventArgs e)
		{
			Dialog2BtnWithInputBox.Show(strings.Lbs_PeoInfo_MsgSayHiTitle, strings.Lbs_PeoInfo_MsgSayHiContent, strings.COM_Send, strings.COM_Cancel, "", new Dialog2BtnWithInputBox.dismissWithClickBtn(this.SayHiDialogHandler), new TextChangedEventHandler(this.SayHiInputChangedHandler), null);
		}
		private void btnExpose_Click(object sender, RoutedEventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Lbs_PeoInfo_MsgExposeTitle, strings.Lbs_PeoInfo_MsgExposeContent, true, strings.COM_Yes, strings.COM_No);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.msgBoxExposeHandler);
		}
		public void msgBoxExposeHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0) == 0)
			{
				ServiceCenter.sceneExpose.doScene(this.mContact.strUserName, ExposeScene.MM_EXPOSE_BOTTLE_PICK, 0u);
			}
		}
		private void SayHiInputChangedHandler(object sender, TextChangedEventArgs e)
		{
			if (sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				if (ToolFunction.getStrDisLen(dialog2BtnWithInputBox.txtIn.get_Text()) <= 20)
				{
					dialog2BtnWithInputBox.btnLeft.set_IsEnabled(true);
					this.mStrSayHiOrigin = dialog2BtnWithInputBox.txtIn.get_Text();
					return;
				}
				if (this.mStrSayHiOrigin != null && this.mStrSayHiOrigin.get_Length() < dialog2BtnWithInputBox.txtIn.get_Text().get_Length())
				{
					dialog2BtnWithInputBox.txtIn.set_Text(this.mStrSayHiOrigin);
					dialog2BtnWithInputBox.txtIn.set_SelectionStart(dialog2BtnWithInputBox.txtIn.get_Text().get_Length());
				}
				this.mStrSayHiOrigin = dialog2BtnWithInputBox.txtIn.get_Text();
			}
		}
		private void SayHiDialogHandler(object sender, int nClickIndex)
		{
			if (nClickIndex == 0 && sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				string text = dialog2BtnWithInputBox.txtIn.get_Text();
				if (text != null)
				{
					int arg_2A_0 = text.get_Length();
				}
				DriftBottleServiceCenter.doSayHiToBottleContact(this.mContact.strUserName, text);
			}
		}
		private void initUI()
		{
			BottleContact bottleContact = this.mContact;
			if (bottleContact == null)
			{
				return;
			}
			if (bottleContact.strSignature != null && bottleContact.strSignature.get_Length() != 0)
			{
				this.topInfoCtrl.SetSignature(bottleContact.strSignature);
			}
			this.topInfoCtrl.SetSex(bottleContact.nSex);
			this.ctrlArea.InfoData = ProfileDataMgr.GetAreaInfo(ToolFunction.GetRegionShow(bottleContact.strProvince, bottleContact.strCity));
			if (this.mContact.strUserName == AccountMgr.strUsrName + "@bottle")
			{
				this.topInfoCtrl.imgHead.set_Source(AccountMgr.getBottletHeadimg());
				this.btnExpose.set_Visibility(1);
				this.btnSendInvite.set_Visibility(1);
				return;
			}
			this.topInfoCtrl.imgHead.set_Source(HeadImgMgr.getHeadImage(this.mContact));
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
		}
		public void SetAppBar()
		{
			base.set_ApplicationBar(new ApplicationBar());
			ApplicationBarMenuItem applicationBarMenuItem = new ApplicationBarMenuItem(strings.Lbs_PeoInfo_BtnExpose);
			applicationBarMenuItem.add_Click(new EventHandler(this.ExposeMenuItem_Click));
			base.get_ApplicationBar().get_MenuItems().Add(applicationBarMenuItem);
			this.setAppBarStyle(base.get_ApplicationBar());
		}
		private void ExposeMenuItem_Click(object sender, EventArgs e)
		{
			this.btnExpose_Click(null, null);
		}
		public static bool GotoThisPage(BottleContact bottleContact_0, bool bIsRemoveCurrentPage = false)
		{
			if (bottleContact_0 == null)
			{
				return false;
			}
			ToolFunction.GotoPageForUserControl("/Source/Plugin/DriftBottle/UI/BotterDetailInfo.xaml", new object[]
			{
				bottleContact_0
			}, bIsRemoveCurrentPage);
			return true;
		}
		public static bool GotoThisPage(string strUserName, bool bIsRemoveCurrentPage = false)
		{
			if (strUserName == null)
			{
				return false;
			}
			if (!(strUserName == AccountMgr.strUsrName + "@bottle") && !(strUserName == AccountMgr.strUsrName))
			{
				ToolFunction.GotoPageForUserControl("/Source/Plugin/DriftBottle/UI/BotterDetailInfo.xaml", new object[]
				{
					strUserName
				}, bIsRemoveCurrentPage);
				return true;
			}
			Account curAccount = AccountMgr.getCurAccount();
			if (curAccount == null)
			{
				return false;
			}
			BottleContact bottleContact_ = new BottleContact
			{
				strUserName = strUserName,
				strCity = curAccount.strCity,
				strProvince = curAccount.strProvince,
				nSex = curAccount.nSex,
				strSignature = curAccount.strSignature
			};
			return BotterDetailInfo.GotoThisPage(bottleContact_, bIsRemoveCurrentPage);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/DriftBottle/UI/BotterDetailInfo.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelProfile = (StackPanel)base.FindName("panelProfile");
			this.topInfoCtrl = (ProfileTopInfoCtrl)base.FindName("topInfoCtrl");
			this.panelContentInfo = (StackPanel)base.FindName("panelContentInfo");
			this.panelAblum = (Grid)base.FindName("panelAblum");
			this.ctrlArea = (ProfileTxtContentCtrl)base.FindName("ctrlArea");
			this.ctrlVerify = (ProfileTxtContentCtrl)base.FindName("ctrlVerify");
			this.btnSendInvite = (Button)base.FindName("btnSendInvite");
			this.btnExpose = (Button)base.FindName("btnExpose");
		}
	}
}
